<?php

/**
 * search actions.
 *
 * @package    iEasy
 * @subpackage search
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class searchActions extends sfActions
{
    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeIndex(sfWebRequest $request)
    {
        //    $this->forward('default', 'module');

    }

    public function executeSearch(sfWebRequest $request)
    {
        $queryStr = $request->getPostParameter('search_key');
        $queryStr = trim($queryStr);
        if ($queryStr) {
            //            $this->queryStr = $queryStr;
            //            $IEasySearchIndex = IEasySearch::getLuceneIndex('All');
            //            $query = Zend_Search_Lucene_Search_QueryParser::parse($queryStr, 'utf-8');
            //            $this->LuceneQuery = $query;
            //            $this->searchResults = $IEasySearchIndex->find($query);
            $this->queryStr = $queryStr;
            $this->news = Doctrine::getTable("News")
                    ->createQuery('n')
                    ->where("n.title like '%" . $queryStr . "%'")
                    ->orWhere("n.tag like '%" . $queryStr . "%'")
                    ->addOrderBy("n.publish_time desc")
                    ->execute();
            $this->videos = Doctrine_Core::getTable("Video")
                    ->createQuery("v")->addWhere("v.title like '%" . $queryStr . "%'")
                    ->orWhere("v.artist like '%" . $queryStr . "%'")
                    ->addOrderBy("v.publish_time desc")
                    ->execute();
            $this->celebritys = Doctrine_Core::getTable("Celebrity")
                    ->createQuery("c")->addWhere("c.name = ?", $queryStr)->execute();
            $this->photoGroups = Doctrine_Core::getTable("PhotoGroup")
                    ->createQuery("p")
                    ->addWhere("p.title like  '%" . $queryStr . "%'")
                    ->orWhere("p.tag like '%" . $queryStr . "%'")
                    ->addOrderBy("p.publish_time desc")
                    ->execute();
        }
        //        $this->forward('search', 'index');
    }
}
